﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Collections;

namespace RAgency.User
{
    public partial class UResults : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetResults();
            }
        }

        private void GetResults()
        {
            ArrayList al = new ArrayList();
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
            conn.Open();
            SqlCommand comm = new SqlCommand("select id_res from results where (id=(select id from users where (login='" + User.Identity.Name + "')))", conn);
            SqlDataReader r = comm.ExecuteReader();
            while (r.Read())
            {
                al.Add(r["id_res"]);
            }
            conn.Close();
            ResultsDDL.DataSource = al;
            ResultsDDL.DataBind();
        }

        protected void ExecuteThis(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
            SqlConnection couu = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
            {
                conn.Open();
                SqlCommand comm = new SqlCommand("select result from results where (id_res=" + ResultsDDL.Text + ")", conn);
                SqlDataReader r = comm.ExecuteReader();
                while (r.Read())
                {
                    couu.Open();
                    SqlDataAdapter adapter = new SqlDataAdapter(r["result"].ToString(), couu);
                    adapter.Fill(ds);
                    break;
                }
                conn.Close();
                couu.Close();
            }
            results.DataSource = ds;
            results.DataBind();
        }
    }
}